{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Triangular 3D surfaces\n",
    "\n",
    "URL: http://matplotlib.org/examples/mplot3d/trisurf3d_demo.html\n",
    "\n",
    "Most examples work across multiple plotting backends, this example is also available for:\n",
    "\n",
    "* [Matplotlib - Triangular 3D surfaces](../matplotlib/trisurf3d_demo.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## HoloViews"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import holoviews as hv\n",
    "hv.extension('plotly')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Define data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "n_radii = 8\n",
    "n_angles = 36\n",
    "\n",
    "# Make radii and angles spaces (radius r=0 omitted to eliminate duplication).\n",
    "radii = np.linspace(0.125, 1.0, n_radii)\n",
    "angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)\n",
    "\n",
    "# Repeat all angles for each radius.\n",
    "angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)\n",
    "\n",
    "# Convert polar (radii, angles) coords to cartesian (x, y) coords.\n",
    "# (0, 0) is manually added at this stage,  so there will be no duplicate\n",
    "# points in the (x, y) plane.\n",
    "x = np.append(0, (radii*np.cos(angles)).flatten())\n",
    "y = np.append(0, (radii*np.sin(angles)).flatten())\n",
    "\n",
    "# Compute z to make the pringle surface.\n",
    "z = np.sin(-x*y)\n",
    "\n",
    "trisurface = hv.Trisurface((x, y, z))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%output size=150\n",
    "trisurface"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
